home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / xshp15.zip / GENCOS.C < prev    next >
Text File  |  1992-01-01  |  1KB  |  50 lines

  1. /* Generates table of cos(theta) for theta from 0 to pi/2, in
  2.    specified degree increments. */
  3.  
  4. #include <math.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "polygon.h"
  8.  
  9. /* Value from the Borland C++ 3.0 math.h include */
  10. #define PI  3.14159265358979323846
  11.  
  12. void main(void);
  13.  
  14. void main()
  15. {
  16.    double Angle = 0.0;
  17.    int i, j, NumSteps;
  18.    long Fixed;
  19.    double Step;
  20.    FILE *DestFile;
  21.  
  22.    printf("How many steps per degree? ");
  23.    scanf("%d",&NumSteps);
  24.    Step = PI/(180*NumSteps);
  25.  
  26.    if ((DestFile = fopen("costable.inc", "w")) == NULL) {
  27.       printf("Error opening file; not created\n");
  28.       exit(1);
  29.    }
  30.  
  31.    fprintf(DestFile,"; 16.16 fixed-point cosines of angles from\n");
  32.    fprintf(DestFile,"; pi/2, in steps of 1/10 degree.\n");
  33.    for (i = 0; i < 90; i++) {
  34.       fprintf(DestFile," dd ");
  35.       for (j = 0; j < (NumSteps-1); j++) {
  36.          Fixed = DOUBLE_TO_FIXED(cos(Angle));
  37.          Angle = Angle + Step;
  38.          fprintf(DestFile,"0%lxh,", Fixed);
  39.       }
  40.       Fixed = DOUBLE_TO_FIXED(cos(Angle));
  41.       Angle = Angle + Step;
  42.       fprintf(DestFile,"0%lxh\n", Fixed);
  43.    }
  44.    /* Finally, the pi/2 point */
  45.    Fixed = DOUBLE_TO_FIXED(cos(Angle));
  46.    fprintf(DestFile," dd 0%lxh\n", Fixed);
  47.  
  48.    exit(0);
  49. }
  50.